using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

using Microsoft.VisualStudio.DebuggerVisualizers;

using iSonar.iCarus.Gui.Controls;

[assembly: DebuggerVisualizer(typeof(iSonar.iCarus.VisualPKI.DerVisualizer),Target = typeof(System.IO.Stream),Description = "DER Visualizer")]
namespace iSonar.iCarus.VisualPKI {
  public class DerVisualizer : DialogDebuggerVisualizer {
    protected override void Show(IDialogVisualizerService windowService,IVisualizerObjectProvider objectProvider) {
      try {
        Stream _dataStream = objectProvider.GetObject() as System.IO.Stream;
        if (null == _dataStream) {
          return;
        }
        using (Form displayForm = new Form()) {
          Asn1ViewCtrl _ctrl = new Asn1ViewCtrl(null);
          _ctrl.Dock = DockStyle.Fill;
          _ctrl.SetContent(_dataStream);
          displayForm.Controls.Add(_ctrl);
          windowService.ShowDialog(displayForm);
        }
      } catch (Exception) {
        // TODO: obsluga bledow
      }
    }

    public static void TestShowVisualizer(object objectToVisualize) {
      VisualizerDevelopmentHost visualizerHost =
          new VisualizerDevelopmentHost(objectToVisualize, typeof(DerVisualizer));
      visualizerHost.ShowVisualizer();
    }
  }
}
